package com.itheima.test;

import java.util.Random;

public class ArrTest5 {
    public static void main(String[] args) {
        //需求：生成10个1-100之间的随机数存入数组
        //1.求出所有数据的和
        //2.求所有数据的平均数
        //3.统计有多少个数据比平均值小

        int[] arr = new int[10];
        Random r = new Random();
        for (int i = 0; i < arr.length; i++) {
            arr[i] = r.nextInt(100) + 1;
        }
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("数组中所有数据的和为" + sum);
        double average = sum / arr.length;
        System.out.println("数组的平均数为" + average);
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] < average){
                count ++;
            }
        }
        System.out.println("数组中比平均数小的个数有" + count + "个");

        //遍历数组，验证结果
        for (int i = 0; i < 10; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
